 % Copyright (C) 2012 	Paul Bovbel, paul@bovbel.com
 % 						Richard Abrich, abrichr@gmail.com
 %
 % This file is part our empirical study of boosting algorithms (http://code.google.com/p/boosting-study/)
 % 
 % This is free software; you can redistribute it and/or modify
 % it under the terms of the GNU General Public License as published by
 % the Free Software Foundation; either version 3 of the License, or
 % (at your option) any later version.
 % 
 % This source code is distributed in the hope that it will be useful,
 % but WITHOUT ANY WARRANTY; without even the implied warranty of
 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 % GNU General Public License for more details.
 % 
 % You should have received a copy of the GNU General Public License
 % along with this source code. If not, see http://www.gnu.org/licenses/

function [ ] = plot_error( test, margin_train, weak_learners, error_data, label )

i=3;

%plot initial distribution of margins
figure(3);
clf;
cdfplot(margin_train(:,i));
axis([-1 1 0 1]);
ylabel('Cumulative Probability');
xlabel('Margin');
title('Margin Empirical CDF');
drawnow
saveas(gcf,strcat('../paper/fig/', [int2str(test) label '_marginsafter_03']),'png');


%plot cumulative distribution of testing data
figure(3);
clf;
cdfplot(margin_train(:,weak_learners));
axis([-1 1 0 1]);
ylabel('Cumulative Probability');
xlabel('Margin');
title('Margin Empirical CDF');
drawnow
saveas(gcf,strcat('../paper/fig/', [int2str(test) label '_marginsafter_' int2str(weak_learners)]),'png');

figure(3);
clf;
hold on;

plot(error_data(:,1),error_data(:,2),'--')
plot(error_data(:,1),error_data(:,3),'-')
axis([1 error_data(end,1) 0 min([100 2*ceil(max([error_data(:,2); error_data(:,3)]))]) ]);

title({'Error Curves', char(strcat(['Final Training Error = ' num2str(error_data(end,2), 3) '%, Testing Error = ' num2str(error_data(end,3), 3) '%']),' ')});
ylabel('Error (%)');
xlabel('Quantity of Weak Learners');

legend('Training Error','Test Error','Location','Best');

saveas(gcf,strcat('../paper/fig/', [int2str(test) label '_error_plot']),'png');

hold off;
end

